package com.edu.controller;

import com.edu.entity.CommonResult;
import com.edu.entity.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user")
@RefreshScope //开启动态刷新
public class UserController {

    //获取配置信息中的name属性值
    @Value("${spring.application.name}")
    private String msg;
    @GetMapping("/getUserById/{userId}")
    public CommonResult<User> getUserById(@PathVariable("userId") Integer userId){
        CommonResult<User> result = new CommonResult<>();
        Integer code = 200;
        String message = "success(11000)msg:"+msg;
        try {
            User user = new User(userId, "橙", "123");
            result.setResult(user);

        }catch (Exception e){
            code=500;
            message="failed";
        }
        result.setCode(code);
        result.setMessage(message);
        return result;
    }
}
